package be.fedict.drupaltest.parts.installation;

import be.fedict.drupaltest.parts.BasePage;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
 * Drupal installation wizard site info page.
 * 
 * @author Bart Hanssens
 */
public class ConfigureSitePage  extends BasePage {
    @FindBy(id="install-configure-form")
    private WebElement form;
    @FindBy(id="edit-site-name")
    private WebElement siteName;
    @FindBy(id="edit-site-mail")
    private WebElement siteMail;
    @FindBy(id="edit-account-name")
    private WebElement adminName;
    @FindBy(id="edit-account-mail")
    private WebElement adminMail;
    @FindBy(id="edit-account-pass-pass1")
    private WebElement adminPass;
    @FindBy(id="edit-account-pass-pass2")
    private WebElement adminPass2;
    @FindBy(id="edit-site-default-country")
    private WebElement serverCountry;
    @FindBy(id="edit-date-default-timezone")
    private WebElement serverZone;
    
    /**
     * Set the general info for the new Drupal website
     * 
     * @param name name of the website
     * @param email general email address
     */
    public void setInfo(String name, String email) {
        siteName.clear();
        siteName.sendKeys(name);
        siteMail.clear();
        siteMail.sendKeys(email);
    }
    
    /**
     * Set the account info for the Drupal admin
     * 
     * @param name user name
     * @param email email address
     * @param pass1 password
     * @param pass2 password confirmation
     */
    public void setAdmin(String name, String email, String pass1, String pass2) {
        adminName.clear();
        adminName.sendKeys(name);
        adminMail.clear();
        adminMail.sendKeys(email);
        adminPass.clear();
        adminPass.sendKeys(pass1);
        adminPass2.clear();
        adminPass2.sendKeys(pass2);
    }
    
    /**
     * Get country option element 
     * 
     * @param country
     * @return element or null
     */
    public WebElement getCountryElement(String country) {
        return getOptionElement(serverCountry, country);
    }
    
    /**
     * Get time zone option element
     * 
     * @param zone time zone
     * @return element or null
     */
    public WebElement getZoneElement(String zone) {
        return getOptionElement(serverZone, zone);
    }
    
    /**
     * Set the server info
     * 
     * @param country name of the country
     * @param zone time zone
     */
    public void setServer(String country, String zone) {
        selectOption(serverCountry, zone);
        selectOption(serverZone, zone);
    }
    
    /**
     * Submit form
     */
    public void submit() {
        form.submit();
    }
}
